<%--
  Created by IntelliJ IDEA.
  User: DELL
  Date: 2020/12/10
  Time: 16:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css" >
</head>
<body>
<%--<table class="layui-table">
    <thead>
    <tr>
        <th>部门ID</th>
        <th>部门编号</th>
        <th>部门名称</th>
        <th>部门介绍</th>
        <th>是否启用</th>
        <th>操作</th>
    </tr>
    </thead>
    <c:forEach  items="${requestScope.all}" var="i">
        <tr>
            <td>${i.get("deptid")}</td>
            <td>${i.get("deptNo")}</td>
            <td>${i.get("dname")}</td>
            <td>${i.get("remark")}</td>
            <td>${i.get("status")}</td>
            <td>
                <a href="${pageContext.request.contextPath}/updatedept.jsp?deptid=${i.get("deptid")}&deptNo=${i.get("deptNo")}&dname=${i.get("dname")}&remark=${i.get("remark")}&status=${i.get("status")}"  class="layui-btn layui-btn-normal layui-btn-xs">修改</a>
                <a href="${pageContext.request.contextPath}/dept/delete?deptid=${i.get("deptid")}"  class="layui-btn layui-btn-danger layui-btn-xs">删除</a>
            </td>
        </tr>
    </c:forEach>
</table>--%>



<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
        <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
    </div>
</script>

<script type="text/html" id="barDemo">
    <a href="${pageContext.request.contextPath}/updatedept.jsp?deptid={{d.deptid}}&deptNo={{d.deptNo}}&dname={{d.dname}}&remark={{d.remark}}&status={{d.status}}" class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a href="${pageContext.request.contextPath}/dept/delete?deptid={{d.deptid}}" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


<script src="${pageContext.request.contextPath}/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script>
    layui.use('table', function(){
        var table = layui.table;

        table.render({
            elem: '#test'
            ,url:'${pageContext.request.contextPath}/dept/all'
            ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                ,layEvent: 'LAYTABLE_TIPS'
                ,icon: 'layui-icon-tips'
            }]
            ,title: 't_dept'
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'deptid', title:'部门ID',  fixed: 'left'}
                ,{field:'deptNo', title:'部门编号'}
                ,{field:'dname', title:'部门名称'}
                ,{field:'remark', title:'部门介绍'}
                ,{field:'status', title:'是否启用'}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo'}
            ]]
            ,page: true
        });

        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选');
                    break;

                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            };
        });

        //监听行工具事件
       /* table.on('tool(test)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    obj.del();
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                layer.prompt({
                    formType: 2
                    ,value: data.email
                }, function(value, index){
                    obj.update({
                        email: value
                    });
                    layer.close(index);
                });
            }
        });*/
    });
</script>
</body>
</html>
